Imports DiceShenanigensUserControls

Module MainModule
   Friend FormGrid As frmGrid = Nothing
   Friend FormCreate As frmCreate = Nothing
   Friend randGenerator As New Random(Now.Millisecond)
   Friend points() As Integer = {0}
   Friend owners() As Integer = {0}
   'Friend playerTurn As PlayerNumber

   ''' <summary>
   ''' Beginning of the program. Calls subs that make the connection and sets up the table. 
   ''' Then creates the new form
   ''' </summary>
   ''' <remarks></remarks>
   Public Sub main()

      '' Default setup
      'makeConnection()
      'setUpTable()
      'Application.Run(frmStart)


      '' Go to game grid
      'grid = New frmGrid(2, GridSize.Large, Color.Crimson, Color.ForestGreen)
      'Application.Run(grid)


      '' Make random grid and call game grid
      'makeRandomArray(GridSize.Large)
      'grid = New frmGrid(2, GridSize.Large, Color.Crimson, Color.ForestGreen)
      'Application.Run(grid)

      ' Go to creator
      FormCreate = New frmCreate(2, GridSize.Large, Color.Crimson, Color.ForestGreen)
      Application.Run(FormCreate)

   End Sub

   ''' <summary>
   ''' 
   ''' </summary>
   ''' <param name="size"></param>
   ''' <remarks></remarks>
   Public Sub makeRandomArray(ByVal size As GridSize)

      Dim aSize As Integer = size * size

      ReDim points(aSize)
      ReDim owners(aSize)

      For x As Integer = 0 To aSize

         Dim b(aSize) As Byte
         System.Security.Cryptography.RandomNumberGenerator.Create.GetNonZeroBytes(b)

         owners(x) = (b(x) Mod 2) + 1
         points(x) = (b(x) Mod 10) + 1
      Next

   End Sub

   ''' <summary>
   ''' 
   ''' </summary>
   ''' <param name="a"></param>
   ''' <returns></returns>
   ''' <remarks></remarks>
   Public Function ArrayToString(ByVal a As Array) As String

      Dim newA As String = ""

      For i As Integer = 0 To a.Length - 1
         If i = a.Length - 1 Then
            newA &= a(i).ToString
         Else
            newA &= a(i).ToString & ","
         End If
      Next

      Return newA
   End Function

   ''' <summary>
   ''' 
   ''' </summary>
   ''' <param name="s"></param>
   ''' <param name="needle"></param>
   ''' <returns></returns>
   ''' <remarks></remarks>
   Public Function StringToArray(ByVal s As String, ByVal needle As Char) As Integer()

      Dim t() As String = s.Split(needle)
      Dim size As Integer = t.Length - 1
      Dim r(size) As Integer

      For i As Integer = 0 To size
         r(i) = Convert.ToInt32(t(i))
      Next

      Return r

   End Function

End Module